
'use strict';
// app/extend/helper.js
module.exports = {
  sha256(ms) {
    const { app } = this;
    let crypto;
    try {
      crypto = require('crypto');
    } catch (err) {
      console.log('不支持 crypto');
      return;
    }
    const hash = crypto.createHmac('sha256', app.config.encryption.secret)
      .update(ms)
      .digest('hex');
    return hash;
  },
  sha1(ms) {
    const { app } = this;
    let crypto;
    try {
      crypto = require('crypto');
    } catch (err) {
      console.log('不支持 crypto');
      return;
    }
    const hash = crypto.createHmac('sha1', app.config.encryption.secret)
      .update(ms)
      .digest('hex');
    return hash;
  },
  md5(ms) {
    const { app } = this;
    let crypto;
    try {
      crypto = require('crypto');
    } catch (err) {
      console.log('不支持 crypto');
      return;
    }
    const hash = crypto.createHmac('md5', app.config.encryption.secret)
      .update(ms)
      .digest('hex');
    return hash;
  },
};
